package iso3.pt.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

import iso3.pt.dao.PtDAO;
import iso3.pt.model.Alumno;
import iso3.pt.model.Asignatura;

public class AnadirNota extends ActionSupport implements Preparable{
	private Alumno alum;
	private Asignatura asig;
	private PtDAO dao;
	private String dniAlumno;
	private String codAsignatura;
	
	public String getCodAsignatura() {
		return codAsignatura;
	}
	public void setCodAsignatura(String codAsignatura) {
		this.codAsignatura = codAsignatura;
	}
	public PtDAO getDao() {
		return dao;
	}
	public void setDao(PtDAO dao) {
		this.dao = dao;
	}
	public String getDniAlumno() {
		return dniAlumno;
	}
	public void setDniAlumno(String dniAlumno) {
		this.dniAlumno = dniAlumno;
	}
	public Alumno getAlum() {
		return alum;
	}
	public void setAlum(Alumno alum) {
		this.alum = alum;
	}
	public Asignatura getAsig() {
		return asig;
	}
	public void setAsig(Asignatura asig) {
		this.asig = asig;
	}
	@Override
	public void prepare() throws Exception {
		dao= PtDAO.getInstance();				
	}
	
	public String execute(){
		Map<String,Object> session=ActionContext.getContext().getSession();
		asig= (Asignatura)session.get("asig");
		alum= dao.getAlumno(Integer.parseInt(dniAlumno));
		session.put("alum", alum);
		codAsignatura= Integer.toString(asig.getId());		
		ActionContext.getContext().setSession(session);
		return "ok";
	}
	
	
	
}
